from django.db import models
from django.contrib.auth.models import User

class Position(models.Model):
    position_name = models.CharField(max_length=100, verbose_name='阵地名')
    province = models.CharField(max_length=100, verbose_name='阵地所在省份')
    district = models.CharField(max_length=100, verbose_name='阵地所在区')
    upload_time = models.DateTimeField(auto_now_add=True, verbose_name='上传时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
    status = models.CharField(max_length=100, verbose_name='状态')
    uploader = models.ForeignKey(User, on_delete=models.CASCADE, related_name='uploaded_positions', verbose_name='上传人')
    modifier = models.ForeignKey(User, on_delete=models.CASCADE, related_name='modified_positions', verbose_name='修改人')
    position_intro = models.TextField(verbose_name='阵地简介')
    position_intro_link = models.URLField(verbose_name='阵地简介详细链接')
    culture_highlight = models.TextField(verbose_name='廉洁文化亮点')
    culture_highlight_link = models.URLField(verbose_name='廉洁文化亮点详细链接')
    video_path = models.FileField(upload_to='videos/', verbose_name='视频作品路径')
    video_more_link = models.URLField(verbose_name='视频作品更多链接')
    reservation_method = models.CharField(max_length=255, verbose_name='预约方式')
    visit_duration = models.IntegerField(verbose_name='参观时长')
    position_address = models.CharField(max_length=255, verbose_name='阵地地址')
    image_path = models.ImageField(upload_to='images/', verbose_name='图片路径',default='')
    image_more_link = models.URLField(verbose_name='图片更多链接')
    exhibition_outline = models.TextField(verbose_name='展陈大纲')
    exhibition_outline_link = models.URLField(verbose_name='展陈大纲详细链接')
    coordinate = models.CharField(max_length=255, verbose_name='坐标')

    def __str__(self):
        return self.position_name

    class Meta:
        verbose_name = '阵地'
        verbose_name_plural = '阵地'

# 问题
class Question(models.Model):
    SINGLE_CHOICE = 1
    MULTIPLE_CHOICE = 2
    TRUE_FALSE = 3

    QUESTION_TYPE_CHOICES = [
        (SINGLE_CHOICE, '单选'),
        (MULTIPLE_CHOICE, '多选'),
        (TRUE_FALSE, '判断'),
    ]

    text = models.CharField(max_length=255)
    question_type = models.IntegerField(choices=QUESTION_TYPE_CHOICES)

    def __str__(self):
        return self.text

# 答案
class Answer(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    text = models.CharField(max_length=255)
    is_correct = models.BooleanField(default=False)

    def __str__(self):
        return self.text


class Product(models.Model):
    name = models.CharField(max_length=100)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    discounted_price = models.DecimalField(max_digits=10, decimal_places=2,null=True)
    detail_link = models.URLField(null=True, blank=True)
    image = models.ImageField(upload_to='products/', null=True, blank=True)

    def __str__(self):
        return self.name